import { _Get, _Post } from "./request";

// 登录
export const login = (data: USER.form) =>
  _Post<string, USER.form>("/login", data);

// 注销登录
export const logout = () => _Get<boolean, null>("/logout", null);

// 注册
export const register = (user: USER.form) =>
  _Post<boolean, USER.form>("/user/register", user);

// 修改用户信息
export const updateUser = (user: USER.form) =>
  _Post<boolean, USER.form>("/user/updateUserInfo", user);

// 修改头像
export const updateAvatar = (id: number, header: string) =>
  _Get<boolean, { id: number; header: string }>("/user/updateAvatar", {
    id: id,
    header: header,
  });

// 修改密码
export const updatePassword = (form: USER.password) =>
  _Post<string, USER.password>("/user/updatePassword", form);

// 用户个人信息by用户名
export const getUserInfo = (name: string) =>
  _Get<USER.info, { username: string }>("/user/infoByUsername", {
    username: name,
  });

// 用户个人信息byUid
export const getUserInfoById = (id: number) =>
  _Get<USER.info, { id: number }>("/user/infoByUid", {
    id: id,
  });

// 添加用户模糊查询
export const fuzzyQueryByAddUser = (id: number, key: string) =>
  _Get<Array<USER.info>, { uid: number; key: string }>(
    "/user/fuzzyQueryByAddUser",
    {
      uid: id,
      key: key,
    }
  );

// 发起好友申请消息
export const sendUserApply = (data: USER.apply) =>
  _Post<number, USER.apply>("/user/addApply", data);

// 查找用户收到的好友申请信息
export const getAddMsg = (id: number) =>
  _Get<Array<USER.apply>, { id: number }>("/user/getAddMsg", {
    id: id,
  });

// 同意好友申请
export const agreeApply = (id: number, fid: number) =>
  _Get<boolean, { id: number; fid: number }>("/user/agreeApply", {
    id: id,
    fid: fid,
  });

// 获取好友列表
export const getFriendList = (id: number) =>
  _Get<USER.info, { id: number }>("/user/getFriendList", {
    id: id,
  });

// 获取未读的消息
export const getUnreadMsg = (id: number) =>
  _Get<CHAT.msg[], { id: number }>("/msg/getUnreadMsgById", {
    id: id,
  });

// 添加会话列表
export const addChatList = (fid: number, tid: number) =>
  _Get<CHAT.msg[], { fid: number; tid: number }>("/msg/addContact", {
    fid: fid,
    tid: tid,
  });

// 获取会话列表
export const selectChatList = (id: number) =>
  _Get<USER.info[], { id: number }>("/msg/getContact", {
    id: id,
  });
